package com.simple.simple_view.controller.video;

import com.simple.simple_view.domain.ResponseResult;
import com.simple.simple_view.domain.enums.AppHttpCodeEnum;
import com.simple.simple_view.domain.system.RedisSystemParam;
import com.simple.simple_view.domain.system.SystemParam;
import com.simple.simple_view.exception.SystemException;
import com.simple.simple_view.service.HotVideoService;
import io.jsonwebtoken.lang.Strings;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/*
 *@description: 榜单接口
 *@author: hisen
 *@Time: 2023/11/1  10:37
 */
@RestController
@RequestMapping("/video")
public class HotVideoController {
    @Resource
    HotVideoService hotVideoService;
    @GetMapping("/hotVideo")
    public ResponseResult hotVideo(@RequestParam String type){
        if(!Strings.hasText(type)){
            throw new SystemException(AppHttpCodeEnum.HOT_TYPE_NOT_NULL);
        }
        if(SystemParam.DAY_HOT_TYPE.equals(type)){
            return hotVideoService.getTopNHotVideos(0, SystemParam.DAY_HOT_SIZE, RedisSystemParam.DAY_HOT_VIDEO_KEY);
        }else if(SystemParam.WEEK_HOT_TYPE.equals(type)){
            return hotVideoService.getTopNHotVideos(0,SystemParam.WEEK_HOT_SIZE,RedisSystemParam.WEEK_HOT_VIDEO_KEY);
        }else{
            return ResponseResult.errorResult(AppHttpCodeEnum.HOT_TYPE_ERROR);
        }
    }
}
